import express from 'express';
import multer from 'multer';

const app = express();
const upload = multer({ dest: 'uploads/' });

// 测试文件上传端点
app.post('/test-upload', upload.single('image'), (req, res) => {
  console.log('🔍 测试上传调试信息:', {
    bodyFields: Object.keys(req.body || {}),
    file: req.file ? {
      originalname: req.file.originalname,
      fieldname: req.file.fieldname,
      mimetype: req.file.mimetype,
      size: req.file.size
    } : 'no file'
  });

  if (!req.file) {
    return res.status(400).json({ error: 'No file uploaded' });
  }

  res.json({
    success: true,
    message: 'File uploaded successfully',
    file: {
      originalname: req.file.originalname,
      fieldname: req.file.fieldname
    }
  });
});

app.listen(4001, () => {
  console.log('测试服务器运行在端口 4001');
});
